package com.beiye.drivertransport.safelearn;

import android.content.Context;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.ActivityCompat;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.android.frame.adapter.CommonAdapter;
import com.android.frame.adapter.ViewHolder;
import com.beiye.drivertransport.R;
import com.beiye.drivertransport.SubActivity.NewSpecifiedAndCourseDetailsActivity;
import com.beiye.drivertransport.SubActivity.SpecifiedLearningCourseDetails1Activity;
import com.beiye.drivertransport.SubActivity.SpecifiedLearningCourseDetailsAgainActivity;
import com.beiye.drivertransport.activity.TwoBaseAty;
import com.beiye.drivertransport.bean.LoginUserBean;
import com.beiye.drivertransport.bean.MineUseBean;
import com.beiye.drivertransport.bean.SpecifiedLearnIngHomeBean;
import com.beiye.drivertransport.bean.SpecifiedLearningCourseBean;
import com.beiye.drivertransport.bean.SpecifiedPhotoBean;
import com.beiye.drivertransport.config.AppInterfaceConfig;
import com.beiye.drivertransport.http.Login;
import com.beiye.drivertransport.utils.CameraCanUseUtils;
import com.beiye.drivertransport.utils.FileUtil;
import com.beiye.drivertransport.utils.LogUtils;
import com.beiye.drivertransport.utils.TiShiDialog;
import com.beiye.drivertransport.utils.ToastUtil;
import com.beiye.drivertransport.utils.UserManger;
import com.beiye.drivertransport.utils.Utils;
import com.beiye.drivertransport.view.MyListView;
import com.beiye.drivertransport.view.ShowGridView;
import com.githang.statusbar.StatusBarCompat;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.StringCallback;
import com.squareup.picasso.Picasso;

import org.xutils.common.Callback;
import org.xutils.http.RequestParams;
import org.xutils.x;

import java.io.Serializable;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;


import butterknife.OnClick;
import okhttp3.Call;
import okhttp3.Response;

//日常培训指定计划课程列表
public class SubSpecifiedLearningHome1Activity extends TwoBaseAty {

    ImageView img_safeback;

    TextView tv_title;

    TextView tv_setChLength;

    TextView tv_actualChLength;

    TextView tv_learnphoto1;

    TextView supermarket;//课程超市

    ShowGridView gv_parent;

    MyListView lv_course;

    View empty_view;

    TextView tvQuestionsInves;


    private static final int REQUEST_EXTERNAL_STORAGE = 1;
    private static String[] PERMISSIONS_STORAGE = {
            "android.permission.READ_EXTERNAL_STORAGE",
            "android.permission.WRITE_EXTERNAL_STORAGE"};
    ArrayList<SpecifiedLearningCourseBean.RowsBean> courseList = new ArrayList<>();
    ArrayList<SpecifiedLearningCourseBean.RowsBean> courseList1 = new ArrayList<>();
    ArrayList<Integer> LengthList = new ArrayList<>();
    private SpecifiedLearningAdapter specifiedLearningAdapter;
    private List<SpecifiedLearningCourseBean.RowsBean> courseDetailList;
    private int rtype;

    private List<SpecifiedPhotoBean.RowsBean> photoList = new ArrayList<>();

    private int photoMark = 0; //拍照张数
    private int takePhotoInterval = 0; //拍照间隔
    private int mtPhotoNo = 0;
    private int actualChLength;//已学时长
    private int setChLength;//课程总时长
    private String orgId;
    private int qnSn;
    private int signMark;
    private int sn;


    @Override
    public int getLayoutId() {
        return R.layout.activity_sub_specified_learning_home1;
    }

    public void onClick(View view) {
        int id = view.getId();
        if (id == R.id.img_safeback) {
            finish();
        } else if (id == R.id.supermarket) {//课程超市
            if (Utils.isFastClicker()) {
                return;
            }
            String actualChLengthstr = tv_actualChLength.getText().toString().trim();
            if (actualChLengthstr.equals("0%")) {
                SharedPreferences sp = getSharedPreferences("SubSpecifiedLearningHomeActivity",
                        Context.MODE_PRIVATE);
                int readInterval = sp.getInt("readInterval", 0);
                String orgId = sp.getString("orgId", "");
                String forbidHour = sp.getString("forbidHour", "");
                int minPer = sp.getInt("minPer", 0);
                int Mark = sp.getInt("Mark", 0);
                int photoMark = sp.getInt("photoMark", 0);
                int signMark = sp.getInt("signMark", 0);
                String statYm = sp.getString("statYm", "");
                int setChLength = sp.getInt("setChLength", 0);
                int learnsn = sp.getInt("sn", 0);
                int faceRecgMark = sp.getInt("faceRecgMark", 0);
                int qpSn = sp.getInt("qpSn", 0);
                int allowMuT = sp.getInt("allowMuT", 0);
                String photoUrl = sp.getString("photoUrl", "");
                Bundle bundle = new Bundle();
                bundle.putInt("readInterval", readInterval);
                bundle.putString("orgId", orgId);
                bundle.putInt("minPer", minPer);
                bundle.putInt("photoMark", photoMark);
                bundle.putInt("signMark", signMark);
                bundle.putInt("Mark", Mark);
                bundle.putInt("actualChLength", 0);
                bundle.putInt("setChLength", setChLength);
                bundle.putInt("learnsn", learnsn);
                bundle.putInt("faceRecgMark", faceRecgMark);
                bundle.putString("statYm", statYm);
                bundle.putString("forbidHour", forbidHour);
                bundle.putString("photoUrl", photoUrl);
                bundle.putInt("qpSn", qpSn);
                bundle.putInt("allowMuT", allowMuT);
                startActivity(CourseSupermarketHomeActivity.class, bundle);
            } else {
                // int actualChLength = Integer.valueOf(actualChLengthstr).intValue();
                SharedPreferences sp = getSharedPreferences("SubSpecifiedLearningHomeActivity",
                        Context.MODE_PRIVATE);
                int readInterval = sp.getInt("readInterval", 0);
                String orgId = sp.getString("orgId", "");
                int minPer = sp.getInt("minPer", 0);
                int Mark = sp.getInt("Mark", 0);
                int photoMark = sp.getInt("photoMark", 0);
                int signMark = sp.getInt("signMark", 0);
                String statYm = sp.getString("statYm", "");
                int setChLength = sp.getInt("setChLength", 0);
                int learnsn = sp.getInt("sn", 0);
                int faceRecgMark = sp.getInt("faceRecgMark", 0);
                String forbidHour = sp.getString("forbidHour", "");
                String photoUrl = sp.getString("photoUrl", "");
                int actualChLength = sp.getInt("actualChLength", 0);
                int qpSn = sp.getInt("qpSn", 0);
                int allowMuT = sp.getInt("allowMuT", 0);
                Bundle bundle = new Bundle();
                bundle.putInt("readInterval", readInterval);
                bundle.putString("orgId", orgId);
                bundle.putInt("minPer", minPer);
                bundle.putInt("photoMark", photoMark);
                bundle.putInt("signMark", signMark);
                bundle.putInt("Mark", Mark);
                bundle.putInt("actualChLength", actualChLength);
                bundle.putInt("setChLength", setChLength);
                bundle.putString("forbidHour", forbidHour);
                bundle.putString("statYm", statYm);
                bundle.putInt("learnsn", learnsn);
                bundle.putInt("faceRecgMark", faceRecgMark);
                bundle.putString("photoUrl", photoUrl);
                bundle.putInt("qpSn", qpSn);
                bundle.putInt("allowMuT", allowMuT);
                startActivity(CourseSupermarketHomeActivity.class, bundle);
            }
        } else if (id == R.id.tv_learnphoto1) {
            String learnphoto = tv_learnphoto1.getText().toString();
            if (learnphoto.equals("查看学习照片")) {
                if (photoList.size() == 0) {
                    showToast("暂无拍照图片");
                    gv_parent.setVisibility(View.GONE);
                } else {
                    tv_learnphoto1.setText("收起图片");
                    gv_parent.setVisibility(View.VISIBLE);
                }

            } else if (learnphoto.equals("收起图片")) {
                tv_learnphoto1.setText("查看学习照片");
                gv_parent.setVisibility(View.GONE);
            }
        } else if (id == R.id.tv_questions_inves) {
            Bundle bundle = new Bundle();
            bundle.putString("orgId", orgId);
            bundle.putInt("relSn", sn);
            bundle.putInt("signMark", signMark);
            startActivity(QuestionInvestigationActivity.class, bundle);
        }
    }

    @Override
    public void initData() {
        img_safeback = (ImageView) findViewById(R.id.img_safeback);
        tv_title = (TextView) findViewById(R.id.tv_title);
        tv_setChLength = (TextView) findViewById(R.id.tv_setChLength);
        tv_actualChLength = (TextView) findViewById(R.id.tv_actualChLength);
        tv_learnphoto1 = (TextView) findViewById(R.id.tv_learnphoto1);
        supermarket= (TextView)findViewById(R.id.supermarket);
        gv_parent = (ShowGridView) findViewById(R.id.gv_parent);
        lv_course = (MyListView) findViewById(R.id.lv_course);
        empty_view = (View) findViewById(R.id.empty_view);
        tvQuestionsInves = (TextView) findViewById(R.id.tv_questions_inves);

        StatusBarCompat.setStatusBarColor(this, Color.parseColor("#1F80C4"));
        Bundle bundle = getIntent().getExtras();
        int minPer = bundle.getInt("minPer"); //学习能力值
        rtype = bundle.getInt("rtype");
        qnSn = bundle.getInt("qnSn");
        LogUtils.e("测试", "initData: " + rtype);
        int readInterval = bundle.getInt("readInterval");
        signMark = bundle.getInt("signMark");
        int Mark = bundle.getInt("Mark");
        photoMark = bundle.getInt("photoMark"); //拍照次数
        orgId = bundle.getString("orgId");
        sn = bundle.getInt("sn");
        String statYm = bundle.getString("statYm");
        actualChLength = bundle.getInt("actualChLength"); //已学习时长
        setChLength = bundle.getInt("setChLength"); //课程总时长
        int chNo = bundle.getInt("chNo"); //学时数
        int checkMark = bundle.getInt("checkMark"); //抽查标记
        int finishMark = bundle.getInt("finishMark"); //完成标记
        int faceRecgMark = bundle.getInt("faceRecgMark"); //人脸识别标记
        int allowMuT = bundle.getInt("allowMuT");
        String forbidHour = bundle.getString("forbidHour"); //禁学时间段
        String photoUrl = bundle.getString("photoUrl"); //头像
        String chName = bundle.getString("chName");
        int qpSn = bundle.getInt("qpSn");

        if (finishMark >= 1 && qnSn != 0) {
            tvQuestionsInves.setVisibility(View.VISIBLE);
        }

        SharedPreferences staticData = getSharedPreferences("StaticData", Context.MODE_PRIVATE);
        mtPhotoNo = staticData.getInt("mtPhotoNo", 0);

        SharedPreferences sp1 = getSharedPreferences("SubSpecifiedLearningHomeActivity",
                Context.MODE_PRIVATE);
        SharedPreferences.Editor edit1 = sp1.edit();
        edit1.putInt("photoMark", photoMark);
        edit1.putInt("signMark", signMark);
        edit1.putInt("minPer", minPer);
        edit1.putInt("readInterval", readInterval);
        edit1.putInt("Mark", Mark);
        edit1.putInt("sn", sn);
        edit1.putInt("checkMark", checkMark);
        edit1.putInt("finishMark", finishMark);
        edit1.putInt("setChLength", setChLength);
        edit1.putInt("faceRecgMark", faceRecgMark);
        edit1.putString("orgId", orgId);
        edit1.putString("statYm", statYm);
        edit1.putString("forbidHour", forbidHour);
        edit1.putString("photoUrl", photoUrl);
        edit1.putInt("qpSn", qpSn);
        edit1.putInt("allowMuT", allowMuT);
        edit1.commit();

        if (chName.equals("")) {
            tv_title.setText("");
        } else {
            tv_title.setText(chName);
        }
        if (chNo == 0) {
            tv_setChLength.setText("0");
        } else {
            tv_setChLength.setText(chNo + "");
        }
        initUi();

    }


    private void initUi() {

        lv_course.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {

                SharedPreferences sp1 = getSharedPreferences("SubSpecifiedLearningHomeActivity", Context.MODE_PRIVATE);
                String forbidHour = sp1.getString("forbidHour", "");
                String statYm = sp1.getString("statYm", "");
                int allowMuT = sp1.getInt("allowMuT", 0);
                if (!forbidHour.equals("")) {
                    String s1 = forbidHour.split(",")[0];
                    String s2 = forbidHour.split(",")[1];
                    SimpleDateFormat df = new SimpleDateFormat("HH:mm:ss");//设置日期格式
                    //初始化
                    Date nowTime = null;
                    Date beginTime = null;
                    Date endTime = null;
                    if (s1.length() == 2) {
                        if (Integer.parseInt(s1) <= Integer.parseInt(s2)) {
                            if (s1.length() == 1) {
                                try {

                                    //定义开始时间
                                    beginTime = df.parse("0" + s1 + ":00" + ":00");

                                } catch (Exception e) {
                                    e.printStackTrace();
                                }
                            } else {
                                try {
                                    //定义开始时间
                                    beginTime = df.parse(s1 + ":00" + ":00");

                                } catch (Exception e) {
                                    e.printStackTrace();
                                }
                            }
                            if (s2.length() == 1) {
                                try {

                                    //定义开始时间
                                    endTime = df.parse("0" + s2 + ":59" + ":59");

                                } catch (Exception e) {
                                    e.printStackTrace();
                                }
                            } else {
                                try {
                                    //定义开始时间
                                    endTime = df.parse(s2 + ":59" + ":59");

                                } catch (Exception e) {
                                    e.printStackTrace();
                                }
                            }
                            try {
                                //格式化当前时间格式
                                nowTime = df.parse(df.format(new Date()));
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                            //调用判断方法
                            boolean flag = FileUtil.belongCalendar(nowTime, beginTime, endTime);
                            if (flag) {
                                //处于规定的时间段内，执行对应的逻辑代码
                                TiShiDialog.Builder builder1 = new TiShiDialog.Builder(SubSpecifiedLearningHome1Activity.this);
                                builder1.setMessage("安全第一，现在是休息时间，明天再来学吧！");
                                builder1.setTitle("提示:");
                                builder1.setPositiveButton("我知道", new DialogInterface.OnClickListener() {
                                    public void onClick(DialogInterface dialog, int which) {
                                        dialog.dismiss();
                                        //设置你的操作事项
                                    }
                                });
                                builder1.create().show();
                                return;
                            }
                        } else {

                            if (s2.length() == 1) {
                                try {
                                    //定义开始时间
                                    beginTime = df.parse("0" + s2 + ":00" + ":00");

                                } catch (Exception e) {
                                    e.printStackTrace();
                                }
                            } else {
                                try {
                                    //定义开始时间
                                    beginTime = df.parse(s2 + ":00" + ":00");

                                } catch (Exception e) {
                                    e.printStackTrace();
                                }
                            }
                            if (s1.length() == 1) {
                                try {

                                    //定义开始时间
                                    endTime = df.parse("0" + s1 + ":59" + ":59");

                                } catch (Exception e) {
                                    e.printStackTrace();
                                }
                            } else {
                                try {
                                    //定义开始时间
                                    endTime = df.parse(s1 + ":59" + ":59");

                                } catch (Exception e) {
                                    e.printStackTrace();
                                }
                            }
                            try {
                                //格式化当前时间格式
                                nowTime = df.parse(df.format(new Date()));
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                            //调用判断方法
                            boolean flag = FileUtil.belongCalendar(nowTime, beginTime, endTime);
                            if (!flag) {
                                //处于规定的时间段内，执行对应的逻辑代码
                                TiShiDialog.Builder builder1 = new TiShiDialog.Builder(SubSpecifiedLearningHome1Activity.this);
                                builder1.setMessage("安全第一，现在是休息时间，明天再来学吧！");
                                builder1.setTitle("提示:");
                                builder1.setPositiveButton("我知道", new DialogInterface.OnClickListener() {
                                    public void onClick(DialogInterface dialog, int which) {
                                        dialog.dismiss();
                                        //设置你的操作事项
                                    }
                                });
                                builder1.create().show();

                                return;

                            }
                        }
                    } else {
                        if (s1.length() == 1) {
                            try {

                                //定义开始时间
                                beginTime = df.parse("0" + s1 + ":00" + ":00");

                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                        } else {
                            try {
                                //定义开始时间
                                beginTime = df.parse(s1 + ":00" + ":00");

                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                        }
                        if (s2.length() == 1) {
                            try {

                                //定义开始时间
                                endTime = df.parse("0" + s2 + ":59" + ":59");

                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                        } else {
                            try {
                                //定义开始时间
                                endTime = df.parse(s2 + ":59" + ":59");

                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                        }
                        try {
                            //格式化当前时间格式
                            nowTime = df.parse(df.format(new Date()));
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                        //调用判断方法
                        boolean flag = FileUtil.belongCalendar(nowTime, beginTime, endTime);
                        if (flag) {
                            //处于规定的时间段内，执行对应的逻辑代码
                            TiShiDialog.Builder builder1 = new TiShiDialog.Builder(SubSpecifiedLearningHome1Activity.this);
                            builder1.setMessage("安全第一，现在是休息时间，明天再来学吧！");
                            builder1.setTitle("提示:");
                            builder1.setPositiveButton("我知道", new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog, int which) {
                                    dialog.dismiss();
                                    //设置你的操作事项
                                }
                            });
                            builder1.create().show();

                            return;

                        }
                    }

                    //检测是否有写的权限
                    int permission = ActivityCompat.checkSelfPermission(SubSpecifiedLearningHome1Activity.this,
                            "android.permission.WRITE_EXTERNAL_STORAGE");
                    if (permission != PackageManager.PERMISSION_GRANTED) {
                        // 没有写的权限，去申请写的权限，会弹出对话框
                        ActivityCompat.requestPermissions(SubSpecifiedLearningHome1Activity.this, PERMISSIONS_STORAGE, REQUEST_EXTERNAL_STORAGE);
                        return;
                    }
                    if (!CameraCanUseUtils.isCameraCanUse()) {
                        ToastUtil.showShortToast(SubSpecifiedLearningHome1Activity.this, "请到手机设置界面里找驾运宝允许开启照相");
                    } else {
                        if (specifiedLearningAdapter.getItem(position).getMark() == 0) {
                            SimpleDateFormat df1 = new SimpleDateFormat("yyyy-MM");//设置日期格式
                            try {
                                long statymtime = df1.parse(statYm).getTime();
                                long nowtime = df1.parse(df1.format(new Date())).getTime();
                                if (statymtime < nowtime && allowMuT == 0) {
                                    TiShiDialog.Builder builder1 = new TiShiDialog.Builder(SubSpecifiedLearningHome1Activity.this);
                                    builder1.setMessage("您所在地区不允许补学");
                                    builder1.setTitle("提示:");
                                    builder1.setPositiveButton("我知道", new DialogInterface.OnClickListener() {
                                        public void onClick(DialogInterface dialog, int which) {
                                            dialog.dismiss();
                                            //设置你的操作事项
                                        }
                                    });
                                    builder1.create().show();
                                    return;
                                }
                            } catch (ParseException e) {
                                e.printStackTrace();
                            }

                            showLoadingDialog("");
                            int tcSn = specifiedLearningAdapter.getItem(position).getTcSn();
                            int otcSn = specifiedLearningAdapter.getItem(position).getOtcSn();
                            int sn = specifiedLearningAdapter.getItem(position).getSn();
                            int readLength = specifiedLearningAdapter.getItem(position).getReadLength();
                            courseList1.clear();
                            for (int i = 0; i < courseList.size(); i++) {
                                if (courseList.get(i).getOtcSn() != otcSn && courseList.get(i).getMark() != 1) {
                                    courseList1.add(courseList.get(i));
                                }

                            }

                            //判断是否配置了按计划拍照
                            if (mtPhotoNo != 0) {
                                if (mtPhotoNo != photoList.size()) {
                                    photoMark = (actualChLength + specifiedLearningAdapter.getItem(position).getCourseLength()) / takePhotoInterval - photoList.size() + 1; //获取需拍照张数
                                } else {
                                    photoMark = 0;
                                }
                                photoMark = (photoMark < 0 ? 0 : photoMark);
                            }

                            Bundle bundle = new Bundle();
                            bundle.putInt("actualChLength", actualChLength);
                            bundle.putInt("takePhotoInterval", takePhotoInterval);
                            bundle.putInt("photoNum", photoList.size());
                            bundle.putInt("tcsn", tcSn);
                            bundle.putInt("otcSn", otcSn);
                            bundle.putInt("sn", sn);//用户课程序列号
                            bundle.putInt("readLength", readLength);//保存时间
                            bundle.putSerializable("CourseDetailList", (Serializable) courseList1);
                            SharedPreferences sp = getSharedPreferences("SubSpecifiedLearningHomeActivity",
                                    Context.MODE_PRIVATE);
                            String orgId = sp.getString("orgId", "");
                            int minPer = sp.getInt("minPer", 0);
                            int photoMark = sp.getInt("photoMark", 0);
                            int signMark = sp.getInt("signMark", 0);
                            int learnsn = sp.getInt("sn", 0);
                            int faceRecgMark = sp.getInt("faceRecgMark", 0);
                            int qpSn = sp.getInt("qpSn", 0);
                            String photoUrl = sp.getString("photoUrl", "");
                            bundle.putString("orgId", orgId);
                            bundle.putString("statYm", statYm);
                            bundle.putInt("minPer", minPer);
                            bundle.putInt("photoMark", photoMark);
                            bundle.putInt("signMark", signMark);
                            bundle.putInt("learnsn", learnsn);
                            bundle.putInt("faceRecgMark", faceRecgMark);
                            bundle.putString("photoUrl", photoUrl);
                            bundle.putInt("qpSn", qpSn);
                            startActivity(SpecifiedLearningCourseDetails1Activity.class, bundle);
                        } else if (specifiedLearningAdapter.getItem(position).getMark() == 1) {
//                                TiShiDialog.Builder builder1 = new TiShiDialog.Builder(SubSpecifiedLearningHomeActivity.this);
//                                builder1.setMessage("该课程已学习");
//                                builder1.setTitle("提示:");
//                                builder1.setPositiveButton("我知道", new DialogInterface.OnClickListener() {
//                                    public void onClick(DialogInterface dialog, int which) {
//                                        dialog.dismiss();
//                                        ;
//                                        //设置你的操作事项
//                                    }
//                                });
//                                builder1.create().show();
                            TiShiDialog.Builder builder1 = new TiShiDialog.Builder(SubSpecifiedLearningHome1Activity.this);
                            builder1.setMessage("您已学习了该课程，继续浏览课程将不记录时间");
                            builder1.setTitle("提示:");
                            builder1.setPositiveButton("确定", new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog, int which) {
                                    dialog.dismiss();
                                    int tcSn = specifiedLearningAdapter.getItem(position).getTcSn();
                                    Bundle bundle = new Bundle();
                                    bundle.putInt("tcsn", tcSn);
                                    startActivity(SpecifiedLearningCourseDetailsAgainActivity.class, bundle);
                                    //设置你的操作事项
                                }
                            });
                            builder1.setNegativeButton("取消", new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    dialog.dismiss();

                                }
                            });
                            builder1.create().show();

                        }
                    }

                } else {
                    //检测是否有写的权限
                    int permission = ActivityCompat.checkSelfPermission(SubSpecifiedLearningHome1Activity.this,
                            "android.permission.WRITE_EXTERNAL_STORAGE");
                    if (permission != PackageManager.PERMISSION_GRANTED) {
                        // 没有写的权限，去申请写的权限，会弹出对话框
                        ActivityCompat.requestPermissions(SubSpecifiedLearningHome1Activity.this, PERMISSIONS_STORAGE, REQUEST_EXTERNAL_STORAGE);
                        return;
                    }
                    if (!CameraCanUseUtils.isCameraCanUse()) {
                        ToastUtil.showShortToast(SubSpecifiedLearningHome1Activity.this, "请到手机设置界面里找驾运宝允许开启照相");
                    } else {
                        if (specifiedLearningAdapter.getItem(position).getMark() == 0) {

                            SimpleDateFormat df1 = new SimpleDateFormat("yyyy-MM");//设置日期格式
                            try {
                                long statymtime = df1.parse(statYm).getTime();
                                long nowtime = df1.parse(df1.format(new Date())).getTime();
                                if (statymtime < nowtime && allowMuT == 0) {
                                    TiShiDialog.Builder builder1 = new TiShiDialog.Builder(SubSpecifiedLearningHome1Activity.this);
                                    builder1.setMessage("您所在地区不允许补学");
                                    builder1.setTitle("提示:");
                                    builder1.setPositiveButton("我知道", new DialogInterface.OnClickListener() {
                                        public void onClick(DialogInterface dialog, int which) {
                                            dialog.dismiss();
                                            //设置你的操作事项
                                        }
                                    });
                                    builder1.create().show();
                                    return;
                                }
                            } catch (ParseException e) {
                                e.printStackTrace();
                            }
                            showLoadingDialog("");
                            int tcSn = specifiedLearningAdapter.getItem(position).getTcSn();
                            int otcSn = specifiedLearningAdapter.getItem(position).getOtcSn();
                            int sn = specifiedLearningAdapter.getItem(position).getSn();
                            int readLength = specifiedLearningAdapter.getItem(position).getReadLength();
                            courseList1.clear();
                            for (int i = 0; i < courseList.size(); i++) {
                                if (courseList.get(i).getOtcSn() != otcSn && courseList.get(i).getMark() != 1) {
                                    courseList1.add(courseList.get(i));
                                }

                            }

                            //判断是否配置了按计划拍照
                            if (mtPhotoNo != 0) {
                                if (mtPhotoNo != photoList.size()) {
                                    photoMark = (actualChLength + specifiedLearningAdapter.getItem(position).getCourseLength()) / takePhotoInterval - photoList.size() + 1; //获取需拍照张数
                                } else {
                                    photoMark = 0;
                                }
                                photoMark = (photoMark < 0 ? 0 : photoMark);
                            }

                            Bundle bundle = new Bundle();
                            bundle.putInt("actualChLength", actualChLength);
                            bundle.putInt("takePhotoInterval", takePhotoInterval);
                            bundle.putInt("photoNum", photoList.size());
                            bundle.putInt("tcsn", tcSn);
                            bundle.putInt("otcSn", otcSn);
                            bundle.putInt("sn", sn);//用户课程序列号
                            bundle.putInt("readLength", readLength);//保存时间
                            bundle.putSerializable("CourseDetailList", (Serializable) courseList1);
                            SharedPreferences sp = getSharedPreferences("SubSpecifiedLearningHomeActivity",
                                    Context.MODE_PRIVATE);
                            String orgId = sp.getString("orgId", "");
                            int minPer = sp.getInt("minPer", 0);
                            int photoMark = sp.getInt("photoMark", 0);
                            int signMark = sp.getInt("signMark", 0);
                            int learnsn = sp.getInt("sn", 0);
                            int faceRecgMark = sp.getInt("faceRecgMark", 0);
                            int qpSn = sp.getInt("qpSn", 0);
                            String photoUrl = sp.getString("photoUrl", "");
                            bundle.putString("orgId", orgId);
                            bundle.putString("statYm", statYm);
                            bundle.putInt("minPer", minPer);
                            bundle.putInt("photoMark", photoMark);
                            bundle.putInt("signMark", signMark);
                            bundle.putInt("learnsn", learnsn);
                            bundle.putInt("faceRecgMark", faceRecgMark);
                            bundle.putString("photoUrl", photoUrl);
                            bundle.putInt("qpSn", qpSn);
                            startActivity(SpecifiedLearningCourseDetails1Activity.class, bundle);
                        } else if (specifiedLearningAdapter.getItem(position).getMark() == 1) {
                            TiShiDialog.Builder builder1 = new TiShiDialog.Builder(SubSpecifiedLearningHome1Activity.this);
                            builder1.setMessage("您已学习了该课程，继续浏览课程将不记录时间");
                            builder1.setTitle("提示:");
                            builder1.setPositiveButton("确定", new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog, int which) {
                                    dialog.dismiss();
                                    int tcSn = specifiedLearningAdapter.getItem(position).getTcSn();
                                    Bundle bundle = new Bundle();
                                    bundle.putInt("tcsn", tcSn);
                                    startActivity(SpecifiedLearningCourseDetailsAgainActivity.class, bundle);
                                    //设置你的操作事项
                                }
                            });
                            builder1.setNegativeButton("取消", new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    dialog.dismiss();

                                }
                            });
                            builder1.create().show();
                        }
                    }
                }

            }
        });
    }


    @Override
    public void requestData() {

        LoginUserBean userInfo = UserManger.getUserInfo();
        LoginUserBean.DataBean data = userInfo.getData();
        String userId = data.getUserId();
        SharedPreferences sp1 = getSharedPreferences("SubSpecifiedLearningHomeActivity",
                Context.MODE_PRIVATE);
        int sn = sp1.getInt("sn", 0);
        showLoadingDialog("");
        LogUtils.e("测试", "requestData: " + userId + " " + sn + " " + rtype);
        new Login().getSpecifiedLearningcourser(userId, sn, rtype + "", this, 1);
        //学习照片
        OkGo.get(AppInterfaceConfig.BASE_URL + "course/userTcPhoto/find/" + sn)
                .tag(this)
                .execute(new StringCallback() {
                    @Override
                    public void onSuccess(String s, Call call, Response response) {
                        SpecifiedPhotoBean photoBean = JSON.parseObject(s, SpecifiedPhotoBean.class);
                        List<SpecifiedPhotoBean.RowsBean> rows = photoBean.getRows();
                        photoList.clear();
                        if (rows.size() == 0) {
                            return;
                        }
                        photoList.addAll(rows);
                        MyGridViewSpecifiedAdapter gridViewAdapter = new MyGridViewSpecifiedAdapter(SubSpecifiedLearningHome1Activity.this, photoList);
                        gv_parent.setAdapter(gridViewAdapter);
                    }

                    @Override
                    public void onError(Call call, Response response, Exception e) {
                        super.onError(call, response, e);

                    }
                });
        new Login().getUser(userId, this, 2);//刷新最新头像


    }

    @Override
    protected void onResume() {
        super.onResume();

        SharedPreferences sp1 = getSharedPreferences("SubSpecifiedLearningHomeActivity",
                Context.MODE_PRIVATE);
        String orgId = sp1.getString("orgId", "");
        LoginUserBean userInfo = UserManger.getUserInfo();
        LoginUserBean.DataBean data = userInfo.getData();
        String userId = data.getUserId();//从新获取最新finish
        showLoadingDialog("");
        new Login().getSpecifiedLearningTwo(orgId, userId, 1, 0, 1, 10000, this, 3);//获取所有条数

    }

    @Override
    public void onSuccess(String result, Call call, Response response, int what) {
        if (what == 1) {
            dismissLoadingDialog();
            SpecifiedLearningCourseBean learnCourseBean = JSON.parseObject(result, SpecifiedLearningCourseBean.class);
            List<SpecifiedLearningCourseBean.RowsBean> rows = learnCourseBean.getRows();
            if (rows.size() == 0) {
                lv_course.setEmptyView(empty_view);
                tv_actualChLength.setText("0%");
                return;
            }

            courseList.clear();
            courseList.addAll(rows);
            specifiedLearningAdapter = new SpecifiedLearningAdapter(SubSpecifiedLearningHome1Activity.this, courseList, R.layout.specified_course_item);
            lv_course.setAdapter(specifiedLearningAdapter);

            LengthList.clear();
            for (int i = 0; i < courseList.size(); i++) {
                if (courseList.get(i).getMark() == 1) { //已完成课程
                    LengthList.add(courseList.get(i).getCourseLength());
                }
            }
            if (mtPhotoNo != 0) {
                takePhotoInterval = setChLength / mtPhotoNo;
            }
            int length = 0; //已完成课程时长
            for (Integer num : LengthList) {
                length += num;
            }
            SharedPreferences sp = getSharedPreferences("SubSpecifiedLearningHomeActivity",
                    Context.MODE_PRIVATE);
            int setChLength = sp.getInt("setChLength", 0);
            int finishMark = sp.getInt("finishMark", 0);
            int qpSn = sp.getInt("qpSn", 0);
            SharedPreferences.Editor edit = sp.edit();
            edit.putInt("actualChLength", length);
            edit.commit();
            if (finishMark == 0) {
                if (length == 0 || setChLength == 0) {
                    tv_actualChLength.setText("0%");
                } else {
                    float studyper = (float) length / (float) setChLength;
                    if (studyper < 1) {
                        int studyper1 = (int) (studyper * 100);
                        //  String ss = String.format("%1.2f", studyper1);
                        tv_actualChLength.setText(studyper1 + "%");
                        tv_actualChLength.setTextColor(SubSpecifiedLearningHome1Activity.this.getResources().getColor(R.color.bixue_red));
                    } else {
                        if (qpSn == 0)//未考试
                        {
                            tv_actualChLength.setText(99 + "%");
                            tv_actualChLength.setTextColor(SubSpecifiedLearningHome1Activity.this.getResources().getColor(R.color.bixue_red));
                        } else {//要考试
                            tv_actualChLength.setText(100 + "%");
                            tv_actualChLength.setTextColor(SubSpecifiedLearningHome1Activity.this.getResources().getColor(R.color.holetotal_yellow));
                        }
                    }
                }
            } else {
                tv_actualChLength.setText(100 + "%");
                tv_actualChLength.setTextColor(SubSpecifiedLearningHome1Activity.this.getResources().getColor(R.color.holetotal_gray));
            }
        } else if (what == 2) {
            MineUseBean mineUseBean = JSON.parseObject(result, MineUseBean.class);
            MineUseBean.DataBean data = mineUseBean.getData();
            String photoUrl = data.getPhotoUrl();
            SharedPreferences sp = getSharedPreferences("SubSpecifiedLearningHomeActivity", Context.MODE_PRIVATE);
            SharedPreferences.Editor edit = sp.edit();
            edit.putString("photoUrl", photoUrl);
            edit.commit();
        } else if (what == 3) {
            dismissLoadingDialog();
            SpecifiedLearnIngHomeBean specifiedLearnIngHomeBean = JSON.parseObject(result, SpecifiedLearnIngHomeBean.class);
            List<SpecifiedLearnIngHomeBean.RowsBean> rowList = specifiedLearnIngHomeBean.getRows();
            SharedPreferences sp = getSharedPreferences("SubSpecifiedLearningHomeActivity", Context.MODE_PRIVATE);
            int learnsn = sp.getInt("sn", 0);
            for (int i = 0; i < rowList.size(); i++) {
                if (learnsn == rowList.get(i).getSn()) {
                    int finishMark = rowList.get(i).getFinishMark();
                    SharedPreferences sp1 = getSharedPreferences("SubSpecifiedLearningHomeActivity", Context.MODE_PRIVATE);
                    SharedPreferences.Editor edit = sp1.edit();
                    edit.putInt("finishMark", finishMark);
                    edit.commit();
                }
            }
            requestData();

        }
        super.onSuccess(result, call, response, what);
    }


    //图片列表适配器
    public class MyGridViewSpecifiedAdapter extends BaseAdapter {

        private Context mContext;
        /**
         * 每个分组下的每个子项的 GridView 数据集合
         */
        private List<SpecifiedPhotoBean.RowsBean> itemGridList;

        public MyGridViewSpecifiedAdapter(Context mContext, List<SpecifiedPhotoBean.RowsBean> itemGridList) {
            this.mContext = mContext;
            this.itemGridList = itemGridList;
        }

        @Override
        public int getCount() {
            return itemGridList.size();
        }

        @Override
        public Object getItem(int position) {
            return itemGridList.get(position);
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            if (null == convertView) {
                convertView = View.inflate(mContext, R.layout.gridview_item, null);
            }
            ImageView img_gv = (ImageView) convertView.findViewById(R.id.img_parent);
            String url = itemGridList.get(position).getUrl();

            Picasso.with(mContext).load(Uri.parse(url)).placeholder(R.mipmap.no_data).into(img_gv);
            return convertView;
        }
    }

    //课程列表适配器
    public class SpecifiedLearningAdapter extends CommonAdapter<SpecifiedLearningCourseBean.RowsBean> {
        private Context context;
        private List<SpecifiedLearningCourseBean.RowsBean> mList;
        private PopupWindow mPopWindow;

        public SpecifiedLearningAdapter(Context context, List<SpecifiedLearningCourseBean.RowsBean> mList, int itemLayoutId) {
            super(context, mList, itemLayoutId);
            this.context = context;
            this.mList = mList;
        }

        @Override
        public void convert(ViewHolder holder, final SpecifiedLearningCourseBean.RowsBean item, final int positon) {
            TextView tv_ttName = holder.getView(R.id.tv_ttName);
            TextView tv_courseLength = holder.getView(R.id.tv_courseLength);
            TextView tv_creationDate = holder.getView(R.id.tv_creationDate);
            TextView tv_courseName = holder.getView(R.id.tv_courseName);
            TextView tv_learnyesorno = holder.getView(R.id.tv_parent4);
            TextView tv_buxue = holder.getView(R.id.tv_parent8);
            TextView tv_supermarket = holder.getView(R.id.tv_parent5);
            TextView tv_learnphoto = holder.getView(R.id.tv_learnphoto);//学习照片
            final TextView tv_learn = holder.getView(R.id.tv_learn);
            int otcSn = mList.get(positon).getOtcSn();
            long creationDate = mList.get(positon).getCreationDate();
            int mark = mList.get(positon).getMark();
            int muMark = mList.get(positon).getMuMark();
            String ttName = mList.get(positon).getTtName();
            String courseName = mList.get(positon).getCourseName();
            int courseLength = mList.get(positon).getCourseLength();
            int readLength = mList.get(positon).getReadLength();
            final int sn = mList.get(positon).getSn();
            LogUtils.e("测试", "convert: " + sn);
            if (sn == 0) {
                initphotodata(0);
            } else {
                initphotodata(sn);
            }

            if (ttName == null) {
                tv_ttName.setText("");
            } else {
                tv_ttName.setText(ttName);
            }
            if (courseName == null) {
                tv_courseName.setText("");
            } else {
                tv_courseName.setText(courseName);
            }
            if (courseLength == 0) {
                tv_courseLength.setText("分钟");
            } else {
                tv_courseLength.setText(courseLength + "分钟");
            }
            SharedPreferences sp1 = getSharedPreferences("SubSpecifiedLearningHomeActivity",
                    Context.MODE_PRIVATE);
            int checkMark = sp1.getInt("checkMark", 0);
            int finishMark = sp1.getInt("finishMark", 0);
            if (finishMark == 0) {
                if (mark == 1) {
                    tv_learnyesorno.setVisibility(View.VISIBLE);
                    tv_learnyesorno.setText("已学习");
                    tv_learnyesorno.setBackgroundResource(R.drawable.shape_specified_yes);
                    tv_learn.setText("重新学习");
                    tv_learnphoto.setVisibility(View.VISIBLE);

                } else if (mark == 0) {
                    if (readLength > 0) {
                        tv_learnyesorno.setVisibility(View.VISIBLE);
                        tv_learnyesorno.setText("未学完");
                        tv_learnyesorno.setBackgroundResource(R.drawable.shape_specified_noorange);
                        tv_learn.setText("继续学习");
                        tv_learnphoto.setVisibility(View.VISIBLE);


                    } else {
                        tv_learnyesorno.setVisibility(View.VISIBLE);
                        tv_learnyesorno.setText("未学习");
                        tv_learnyesorno.setBackgroundResource(R.drawable.shape_specified_nored);
                        tv_learn.setText("开始学习");
                        tv_learnphoto.setVisibility(View.GONE);
                    }

                }

            } else {
                if (checkMark == 0) {

                    if (mark == 1) {
                        tv_learnyesorno.setVisibility(View.VISIBLE);
                        tv_learnyesorno.setText("已学习");
                        tv_learnyesorno.setBackgroundResource(R.drawable.shape_specified_yes);
                        tv_learn.setText("重新学习");
                        tv_learnphoto.setVisibility(View.VISIBLE);


                    } else if (mark == 0) {
                        if (readLength > 0) {
                            tv_learnyesorno.setVisibility(View.VISIBLE);
                            tv_learnyesorno.setText("未学完");
                            tv_learnyesorno.setBackgroundResource(R.drawable.shape_specified_noorange);
                            tv_learn.setText("继续学习");
                            tv_learnphoto.setVisibility(View.VISIBLE);

                        } else {
                            tv_learnyesorno.setVisibility(View.VISIBLE);
                            tv_learnyesorno.setText("未学习");
                            tv_learnyesorno.setBackgroundResource(R.drawable.shape_specified_nored);
                            tv_learn.setText("开始学习");
                            tv_learnphoto.setVisibility(View.GONE);
                        }
                    }

                } else {
                    if (mark == 1) {
                        tv_learnyesorno.setVisibility(View.VISIBLE);
                        tv_learnyesorno.setText("已学习");
                        tv_learnyesorno.setBackgroundResource(R.drawable.shape_specified_yes);
                        tv_learn.setVisibility(View.INVISIBLE);
                        //    tv_learn.setText("重新学习");
                        tv_learnphoto.setVisibility(View.VISIBLE);

                    } else if (mark == 0) {

                        if (readLength > 0) {
                            tv_learnyesorno.setVisibility(View.VISIBLE);
                            tv_learnyesorno.setText("未学完");
                            tv_learnyesorno.setBackgroundResource(R.drawable.shape_specified_noorange);
                            tv_learn.setVisibility(View.VISIBLE);
                            tv_learn.setText("继续学习");
                            tv_learnphoto.setVisibility(View.VISIBLE);

                        } else {
                            tv_learnyesorno.setVisibility(View.VISIBLE);
                            tv_learnyesorno.setText("未学习");
                            tv_learnyesorno.setBackgroundResource(R.drawable.shape_specified_nored);
                            tv_learn.setVisibility(View.VISIBLE);
                            tv_learn.setText("开始学习");
                            tv_learnphoto.setVisibility(View.GONE);
                        }

                    }
                }
            }

            if (muMark == 1) {
                tv_buxue.setVisibility(View.VISIBLE);

            } else {
                tv_buxue.setVisibility(View.GONE);
            }
            if (otcSn != 0 && otcSn > 0) {
                tv_supermarket.setVisibility(View.GONE);
            } else {
                tv_supermarket.setVisibility(View.VISIBLE);
            }
            tv_learnphoto.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (Utils.isFastClicker()) {
                        return;
                    }
                    SharedPreferences sp = getSharedPreferences("SubSpecifiedLearningHomeActivity",
                            Context.MODE_PRIVATE);
                    String photourl = sp.getString("photourl" + sn, "");
                    String photourl1 = sp.getString("photourl1" + sn, "");
                    String photourl2 = sp.getString("photourl2" + sn, "");
                    String photourl3 = sp.getString("photourl3" + sn, "");
                    String photourl4 = sp.getString("photourl4" + sn, "");
                    if (photourl.equals("")) {
                        TiShiDialog.Builder builder1 = new TiShiDialog.Builder(SubSpecifiedLearningHome1Activity.this);
                        builder1.setMessage("您在本课程没有学习照片。");
                        builder1.setTitle("提示:");
                        builder1.setPositiveButton("确定", new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int which) {
                                dialog.dismiss();
                                ;
                                //设置你的操作事项
                            }
                        });
                        builder1.create().show();
                    } else {
                        View contentView = LayoutInflater.from(SubSpecifiedLearningHome1Activity.this).inflate(R.layout.popwindow_showphoto_layout, null);
                        mPopWindow = new PopupWindow(contentView,
                                WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT, true);
                        mPopWindow.showAtLocation(tv_title, Gravity.CENTER, 0, 0);
                        TextView tv_dismiss = (TextView) contentView.findViewById(R.id.tv_dismiss);
                        tv_dismiss.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                mPopWindow.dismiss();
                            }
                        });
                        final ImageView img_photo1 = (ImageView) contentView.findViewById(R.id.img_photo1);
                        final ImageView img_photo2 = (ImageView) contentView.findViewById(R.id.img_photo2);
                        final ImageView img_photo3 = (ImageView) contentView.findViewById(R.id.img_photo3);
                        final ImageView img_photo4 = (ImageView) contentView.findViewById(R.id.img_photo4);
                        final ImageView img_photo5 = (ImageView) contentView.findViewById(R.id.img_photo5);
                        if (photourl.contains("aliyuncs.com")) {
                            Picasso.with(context).load(Uri.parse(photourl)).placeholder(R.mipmap.no_data).into(img_photo1);
                        } else {

                            Picasso.with(context).load(Uri.parse(AppInterfaceConfig.getRequestUrl(photourl))).placeholder(R.mipmap.no_data).into(img_photo1);
                        }
                        if (!photourl1.equals("")) {
                            if (photourl1.contains("aliyuncs.com")) {
                                Picasso.with(context).load(Uri.parse(photourl1)).placeholder(R.mipmap.no_data).into(img_photo2);
                            } else {

                                Picasso.with(context).load(Uri.parse(AppInterfaceConfig.getRequestUrl(photourl1))).placeholder(R.mipmap.no_data).into(img_photo2);
                            }
                        } else {
                            img_photo2.setImageResource(R.drawable.normalphoto);
                        }
                        if (!photourl2.equals("")) {
                            if (photourl2.contains("aliyuncs.com")) {
                                Picasso.with(context).load(Uri.parse(photourl2)).placeholder(R.mipmap.no_data).into(img_photo3);
                            } else {

                                Picasso.with(context).load(Uri.parse(AppInterfaceConfig.getRequestUrl(photourl2))).placeholder(R.mipmap.no_data).into(img_photo3);
                            }
                        } else {
                            img_photo3.setImageResource(R.drawable.normalphoto);
                        }
                        if (!photourl3.equals("")) {
                            if (photourl3.contains("aliyuncs.com")) {
                                Picasso.with(context).load(Uri.parse(photourl3)).placeholder(R.mipmap.no_data).into(img_photo4);
                            } else {

                                Picasso.with(context).load(Uri.parse(AppInterfaceConfig.getRequestUrl(photourl3))).placeholder(R.mipmap.no_data).into(img_photo4);
                            }
                        } else {
                            img_photo4.setImageResource(R.drawable.normalphoto);
                        }
                        if (!photourl4.equals("")) {
                            if (photourl4.contains("aliyuncs.com")) {
                                Picasso.with(context).load(Uri.parse(photourl4)).placeholder(R.mipmap.no_data).into(img_photo5);
                            } else {

                                Picasso.with(context).load(Uri.parse(AppInterfaceConfig.getRequestUrl(photourl4))).placeholder(R.mipmap.no_data).into(img_photo5);
                            }
                        } else {
                            img_photo5.setImageResource(R.drawable.normalphoto);
                        }
                    }
                }
            });

            tv_learn.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    SharedPreferences sp1 = getSharedPreferences("SubSpecifiedLearningHomeActivity", Context.MODE_PRIVATE);
                    String forbidHour = sp1.getString("forbidHour", "");
                    if (!forbidHour.equals("")) {
                        String s1 = forbidHour.split(",")[0];
                        String s2 = forbidHour.split(",")[1];
                        SimpleDateFormat df = new SimpleDateFormat("HH:mm:ss");//设置日期格式
                        //初始化
                        Date nowTime = null;
                        Date beginTime = null;
                        Date endTime = null;
                        if (s1.length() == 2) {
                            if (Integer.parseInt(s1) <= Integer.parseInt(s2)) {
                                if (s1.length() == 1) {
                                    try {

                                        //定义开始时间
                                        beginTime = df.parse("0" + s1 + ":00" + ":00");

                                    } catch (Exception e) {
                                        e.printStackTrace();
                                    }
                                } else {
                                    try {
                                        //定义开始时间
                                        beginTime = df.parse(s1 + ":00" + ":00");

                                    } catch (Exception e) {
                                        e.printStackTrace();
                                    }
                                }
                                if (s2.length() == 1) {
                                    try {

                                        //定义开始时间
                                        endTime = df.parse("0" + s2 + ":59" + ":59");

                                    } catch (Exception e) {
                                        e.printStackTrace();
                                    }
                                } else {
                                    try {
                                        //定义开始时间
                                        endTime = df.parse(s2 + ":59" + ":59");

                                    } catch (Exception e) {
                                        e.printStackTrace();
                                    }
                                }
                                try {
                                    //格式化当前时间格式
                                    nowTime = df.parse(df.format(new Date()));
                                } catch (Exception e) {
                                    e.printStackTrace();
                                }
                                //调用判断方法
                                boolean flag = FileUtil.belongCalendar(nowTime, beginTime, endTime);
                                if (flag) {
                                    //处于规定的时间段内，执行对应的逻辑代码
                                    TiShiDialog.Builder builder1 = new TiShiDialog.Builder(SubSpecifiedLearningHome1Activity.this);
                                    builder1.setMessage("安全第一，现在是休息时间，明天再来学吧！");
                                    builder1.setTitle("提示:");
                                    builder1.setPositiveButton("我知道", new DialogInterface.OnClickListener() {
                                        public void onClick(DialogInterface dialog, int which) {
                                            dialog.dismiss();
                                            //设置你的操作事项
                                        }
                                    });
                                    builder1.create().show();

                                    return;

                                }
                            } else {

                                if (s2.length() == 1) {
                                    try {
                                        //定义开始时间
                                        beginTime = df.parse("0" + s2 + ":00" + ":00");

                                    } catch (Exception e) {
                                        e.printStackTrace();
                                    }
                                } else {
                                    try {
                                        //定义开始时间
                                        beginTime = df.parse(s2 + ":00" + ":00");

                                    } catch (Exception e) {
                                        e.printStackTrace();
                                    }
                                }
                                if (s1.length() == 1) {
                                    try {

                                        //定义开始时间
                                        endTime = df.parse("0" + s1 + ":59" + ":59");

                                    } catch (Exception e) {
                                        e.printStackTrace();
                                    }
                                } else {
                                    try {
                                        //定义开始时间
                                        endTime = df.parse(s1 + ":59" + ":59");

                                    } catch (Exception e) {
                                        e.printStackTrace();
                                    }
                                }
                                try {
                                    //格式化当前时间格式
                                    nowTime = df.parse(df.format(new Date()));
                                } catch (Exception e) {
                                    e.printStackTrace();
                                }
                                //调用判断方法
                                boolean flag = FileUtil.belongCalendar(nowTime, beginTime, endTime);
                                if (!flag) {
                                    //处于规定的时间段内，执行对应的逻辑代码
                                    TiShiDialog.Builder builder1 = new TiShiDialog.Builder(SubSpecifiedLearningHome1Activity.this);
                                    builder1.setMessage("安全第一，现在是休息时间，明天再来学吧！");
                                    builder1.setTitle("提示:");
                                    builder1.setPositiveButton("我知道", new DialogInterface.OnClickListener() {
                                        public void onClick(DialogInterface dialog, int which) {
                                            dialog.dismiss();
                                            //设置你的操作事项
                                        }
                                    });
                                    builder1.create().show();

                                    return;

                                }
                            }
                        } else {
                            if (s1.length() == 1) {
                                try {

                                    //定义开始时间
                                    beginTime = df.parse("0" + s1 + ":00" + ":00");

                                } catch (Exception e) {
                                    e.printStackTrace();
                                }
                            } else {
                                try {
                                    //定义开始时间
                                    beginTime = df.parse(s1 + ":00" + ":00");

                                } catch (Exception e) {
                                    e.printStackTrace();
                                }
                            }
                            if (s2.length() == 1) {
                                try {

                                    //定义开始时间
                                    endTime = df.parse("0" + s2 + ":59" + ":59");

                                } catch (Exception e) {
                                    e.printStackTrace();
                                }
                            } else {
                                try {
                                    //定义开始时间
                                    endTime = df.parse(s2 + ":59" + ":59");

                                } catch (Exception e) {
                                    e.printStackTrace();
                                }
                            }
                            try {
                                //格式化当前时间格式
                                nowTime = df.parse(df.format(new Date()));
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                            //调用判断方法
                            boolean flag = FileUtil.belongCalendar(nowTime, beginTime, endTime);
                            if (flag) {
                                //处于规定的时间段内，执行对应的逻辑代码
                                TiShiDialog.Builder builder1 = new TiShiDialog.Builder(SubSpecifiedLearningHome1Activity.this);
                                builder1.setMessage("安全第一，现在是休息时间，明天再来学吧！");
                                builder1.setTitle("提示:");
                                builder1.setPositiveButton("我知道", new DialogInterface.OnClickListener() {
                                    public void onClick(DialogInterface dialog, int which) {
                                        dialog.dismiss();
                                        //设置你的操作事项
                                    }
                                });
                                builder1.create().show();

                                return;

                            }
                        }

                        //检测是否有写的权限
                        int permission = ActivityCompat.checkSelfPermission(SubSpecifiedLearningHome1Activity.this,
                                "android.permission.WRITE_EXTERNAL_STORAGE");
                        if (permission != PackageManager.PERMISSION_GRANTED) {
                            // 没有写的权限，去申请写的权限，会弹出对话框
                            ActivityCompat.requestPermissions(SubSpecifiedLearningHome1Activity.this, PERMISSIONS_STORAGE, REQUEST_EXTERNAL_STORAGE);
                            return;
                        }
                        if (!CameraCanUseUtils.isCameraCanUse()) {

                            ToastUtil.showShortToast(SubSpecifiedLearningHome1Activity.this, "请到手机设置界面里找驾运宝允许开启照相");
                            return;
                        }

                        String learnstr = tv_learn.getText().toString().trim();
                        if (learnstr.equals("重新学习")) {
                            TiShiDialog.Builder builder = new TiShiDialog.Builder(SubSpecifiedLearningHome1Activity.this);
                            builder.setMessage("你确定要重新学习该课程吗?");
                            builder.setTitle("提示:");
                            builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog, int which) {
                                    dialog.dismiss();
                                    SharedPreferences sp1 = getSharedPreferences("SubSpecifiedLearningHomeActivity",
                                            Context.MODE_PRIVATE);
                                    int utchSn = sp1.getInt("sn", 0);
                                    int minPer = sp1.getInt("minPer", 0);
                                    int photoMark = sp1.getInt("photoMark", 0);
                                    int faceRecgMark = sp1.getInt("faceRecgMark", 0);
                                    String photoUrl = sp1.getString("photoUrl", "");
                                    int sn = mList.get(positon).getSn();
                                    int tcSn = mList.get(positon).getTcSn();
                                    Bundle bundle = new Bundle();
                                    bundle.putInt("utchSn", utchSn);
                                    bundle.putInt("sn", sn);
                                    bundle.putInt("tcSn", tcSn);
                                    bundle.putInt("minPer", minPer);
                                    bundle.putInt("photoMark", photoMark);
                                    bundle.putInt("faceRecgMark", faceRecgMark);
                                    bundle.putString("photoUrl", photoUrl);
                                    startActivity(NewSpecifiedAndCourseDetailsActivity.class, bundle);
                                }
                            });

                            builder.setNegativeButton("取消",
                                    new DialogInterface.OnClickListener() {
                                        public void onClick(DialogInterface dialog, int which) {
                                            dialog.dismiss();
                                        }
                                    });
                            builder.create().show();
                        } else if (learnstr.equals("开始学习") || learnstr.equals("继续学习")) {
                            SharedPreferences sp = getSharedPreferences("SubSpecifiedLearningHomeActivity",
                                    Context.MODE_PRIVATE);
                            String statYm = sp.getString("statYm", "");
                            int allowMuT = sp.getInt("allowMuT", 0);
                            SimpleDateFormat df1 = new SimpleDateFormat("yyyy-MM");//设置日期格式
                            try {
                                long statymtime = df1.parse(statYm).getTime();
                                long nowtime = df1.parse(df1.format(new Date())).getTime();
                                if (statymtime < nowtime && allowMuT == 0) {
                                    TiShiDialog.Builder builder1 = new TiShiDialog.Builder(SubSpecifiedLearningHome1Activity.this);
                                    builder1.setMessage("您所在地区不允许补学");
                                    builder1.setTitle("提示:");
                                    builder1.setPositiveButton("我知道", new DialogInterface.OnClickListener() {
                                        public void onClick(DialogInterface dialog, int which) {
                                            dialog.dismiss();
                                            //设置你的操作事项
                                        }
                                    });
                                    builder1.create().show();
                                    return;
                                }
                            } catch (ParseException e) {
                                e.printStackTrace();
                            }

                            showLoadingDialog("");
                            int tcSn = mList.get(positon).getTcSn();
                            int otcSn = mList.get(positon).getOtcSn();
                            int sn = mList.get(positon).getSn();
                            int readLength = mList.get(positon).getReadLength();
                            courseList1.clear();
                            for (int i = 0; i < courseList.size(); i++) {
                                if (courseList.get(i).getOtcSn() != otcSn && courseList.get(i).getMark() != 1) {
                                    courseList1.add(courseList.get(i));
                                }

                            }
                            String orgId = sp.getString("orgId", "");
                            int minPer = sp.getInt("minPer", 0);
                            int photoMark = sp.getInt("photoMark", 0);
                            int signMark = sp.getInt("signMark", 0);
                            int learnsn = sp.getInt("sn", 0);
                            int faceRecgMark = sp.getInt("faceRecgMark", 0);
                            int qpSn = sp.getInt("qpSn", 0);
                            String photoUrl = sp.getString("photoUrl", "");

                            //判断是否配置了按计划拍照
                            if (mtPhotoNo != 0) {
                                if (mtPhotoNo != photoList.size()) {
                                    photoMark = (actualChLength + mList.get(positon).getCourseLength()) / takePhotoInterval - photoList.size() + 1; //获取需拍照张数
                                } else {
                                    photoMark = 0;
                                }
                                photoMark = (photoMark < 0 ? 0 : photoMark);
                            }

                            Bundle bundle = new Bundle();
                            bundle.putInt("actualChLength", actualChLength);
                            bundle.putInt("takePhotoInterval", takePhotoInterval);
                            bundle.putInt("photoNum", photoList.size());
                            bundle.putInt("tcsn", tcSn);
                            bundle.putInt("otcSn", otcSn);
                            bundle.putInt("sn", sn);//用户课程序列号
                            bundle.putInt("readLength", readLength);//保存时间
                            bundle.putSerializable("CourseDetailList", (Serializable) courseList1);
                            bundle.putString("orgId", orgId);
                            bundle.putString("statYm", statYm);
                            bundle.putInt("minPer", minPer);
                            bundle.putInt("photoMark", photoMark); //需拍照张数
                            bundle.putInt("signMark", signMark);
                            bundle.putInt("learnsn", learnsn);
                            bundle.putInt("faceRecgMark", faceRecgMark);
                            bundle.putString("photoUrl", photoUrl);
                            bundle.putInt("qpSn", qpSn);
                            startActivity(SpecifiedLearningCourseDetails1Activity.class, bundle);
                        }
                    } else {
                        //检测是否有写的权限
                        int permission = ActivityCompat.checkSelfPermission(SubSpecifiedLearningHome1Activity.this,
                                "android.permission.WRITE_EXTERNAL_STORAGE");
                        if (permission != PackageManager.PERMISSION_GRANTED) {
                            // 没有写的权限，去申请写的权限，会弹出对话框
                            ActivityCompat.requestPermissions(SubSpecifiedLearningHome1Activity.this, PERMISSIONS_STORAGE, REQUEST_EXTERNAL_STORAGE);
                            return;
                        }
                        if (!CameraCanUseUtils.isCameraCanUse()) {

                            ToastUtil.showShortToast(SubSpecifiedLearningHome1Activity.this, "请到手机设置界面里找驾运宝允许开启照相");
                            return;
                        }

                        String learnstr = tv_learn.getText().toString().trim();
                        if (learnstr.equals("重新学习")) {
                            TiShiDialog.Builder builder = new TiShiDialog.Builder(SubSpecifiedLearningHome1Activity.this);
                            builder.setMessage("你确定要重新学习该课程吗?");
                            builder.setTitle("提示:");
                            builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog, int which) {
                                    dialog.dismiss();
                                    SharedPreferences sp1 = getSharedPreferences("SubSpecifiedLearningHomeActivity",
                                            Context.MODE_PRIVATE);
                                    int utchSn = sp1.getInt("sn", 0);
                                    int minPer = sp1.getInt("minPer", 0);
                                    int photoMark = sp1.getInt("photoMark", 0);
                                    int faceRecgMark = sp1.getInt("faceRecgMark", 0);
                                    String photoUrl = sp1.getString("photoUrl", "");
                                    int sn = mList.get(positon).getSn();
                                    int tcSn = mList.get(positon).getTcSn();
                                    Bundle bundle = new Bundle();
                                    bundle.putInt("utchSn", utchSn);
                                    bundle.putInt("sn", sn);
                                    bundle.putInt("tcSn", tcSn);
                                    bundle.putInt("minPer", minPer);
                                    bundle.putInt("photoMark", photoMark);
                                    bundle.putInt("faceRecgMark", faceRecgMark);
                                    bundle.putString("photoUrl", photoUrl);
                                    startActivity(NewSpecifiedAndCourseDetailsActivity.class, bundle);
                                }
                            });

                            builder.setNegativeButton("取消",
                                    new DialogInterface.OnClickListener() {
                                        public void onClick(DialogInterface dialog, int which) {
                                            dialog.dismiss();
                                        }
                                    });


                            builder.create().show();
                        } else if (learnstr.equals("开始学习") || learnstr.equals("继续学习")) {
                            SharedPreferences sp = getSharedPreferences("SubSpecifiedLearningHomeActivity",
                                    Context.MODE_PRIVATE);
                            String statYm = sp.getString("statYm", "");
                            int allowMuT = sp.getInt("allowMuT", 0);
                            SimpleDateFormat df1 = new SimpleDateFormat("yyyy-MM");//设置日期格式
                            try {
                                long statymtime = df1.parse(statYm).getTime();
                                long nowtime = df1.parse(df1.format(new Date())).getTime();
                                if (statymtime < nowtime && allowMuT == 0) {
                                    TiShiDialog.Builder builder1 = new TiShiDialog.Builder(SubSpecifiedLearningHome1Activity.this);
                                    builder1.setMessage("您所在地区不允许补学");
                                    builder1.setTitle("提示:");
                                    builder1.setPositiveButton("我知道", new DialogInterface.OnClickListener() {
                                        public void onClick(DialogInterface dialog, int which) {
                                            dialog.dismiss();
                                            //设置你的操作事项
                                        }
                                    });
                                    builder1.create().show();
                                    return;
                                }
                            } catch (ParseException e) {
                                e.printStackTrace();
                            }
                            showLoadingDialog("");
                            int tcSn = mList.get(positon).getTcSn();
                            int otcSn = mList.get(positon).getOtcSn();
                            int sn = mList.get(positon).getSn();
                            int readLength = mList.get(positon).getReadLength();

                            courseList1.clear();
                            for (int i = 0; i < courseList.size(); i++) {
                                if (courseList.get(i).getOtcSn() != otcSn && courseList.get(i).getMark() != 1) {
                                    courseList1.add(courseList.get(i));
                                }

                            }


                            String orgId = sp.getString("orgId", "");
                            int minPer = sp.getInt("minPer", 0);
                            int photoMark = sp.getInt("photoMark", 0);
                            int signMark = sp.getInt("signMark", 0);
                            int learnsn = sp.getInt("sn", 0);
                            int faceRecgMark = sp.getInt("faceRecgMark", 0);
                            int qpSn = sp.getInt("qpSn", 0);
                            String photoUrl = sp.getString("photoUrl", "");

                            //判断是否配置了按计划拍照
                            if (mtPhotoNo != 0) {
                                if (mtPhotoNo != photoList.size()) {
                                    photoMark = (actualChLength + mList.get(positon).getCourseLength()) / takePhotoInterval - photoList.size() + 1; //获取需拍照张数
                                } else {
                                    photoMark = 0;
                                }
                                photoMark = (photoMark < 0 ? 0 : photoMark);
                            }
                            Bundle bundle = new Bundle();
                            bundle.putInt("actualChLength", actualChLength);
                            bundle.putInt("takePhotoInterval", takePhotoInterval);
                            bundle.putInt("photoNum", photoList.size());
                            bundle.putInt("tcsn", tcSn);
                            bundle.putInt("otcSn", otcSn);
                            bundle.putInt("sn", sn);//用户课程序列号
                            bundle.putInt("readLength", readLength);//保存时间
                            bundle.putSerializable("CourseDetailList", (Serializable) courseList1);
                            bundle.putString("orgId", orgId);
                            bundle.putString("statYm", statYm);
                            bundle.putInt("minPer", minPer);
                            bundle.putInt("photoMark", photoMark);
                            bundle.putInt("signMark", signMark);
                            bundle.putInt("learnsn", learnsn);
                            bundle.putInt("faceRecgMark", faceRecgMark);
                            bundle.putString("photoUrl", photoUrl);
                            bundle.putInt("qpSn", qpSn);
                            startActivity(SpecifiedLearningCourseDetails1Activity.class, bundle);

                        }

                    }
                }
            });

            if (creationDate > 0) {
                String begin = "";
                try {
                    //yyyy表示年MM表示月dd表示日
                    //yyyy-MM-dd是日期的格式，比如2015-12-12如果你要得到2015年12月12日就换成yyyy年MM月dd日
                    SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd");
                    //进行格式化
                    begin = sdf.format(creationDate);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                tv_creationDate.setVisibility(View.VISIBLE);
                tv_creationDate.setText("学习时间: " + begin);

            } else {
                tv_creationDate.setVisibility(View.GONE);
            }

        }
    }

    private void initphotodata(final int sn) {
        if (sn == 0) {
            return;
        }
        RequestParams params = new RequestParams(AppInterfaceConfig.BASE_URL + "course/userTcPhoto/findTc/" + sn);
        x.http().get(params, new Callback.CommonCallback<String>() {
            @Override
            public void onSuccess(String result) {
                SpecifiedPhotoBean specifiedPhotoBean = JSON.parseObject(result, SpecifiedPhotoBean.class);
                List<SpecifiedPhotoBean.RowsBean> rows = specifiedPhotoBean.getRows();

                if (rows.size() == 0) {
                    SharedPreferences sp = getSharedPreferences("SubSpecifiedLearningHomeActivity",
                            Context.MODE_PRIVATE);
                    SharedPreferences.Editor edit = sp.edit();
                    edit.putString("photourl" + sn, "");
                    edit.commit();
                    return;
                }
                if (rows.size() == 1) {
                    String url = specifiedPhotoBean.getRows().get(0).getUrl();
                    if (url == null) {
                        SharedPreferences sp = getSharedPreferences("SubSpecifiedLearningHomeActivity",
                                Context.MODE_PRIVATE);
                        SharedPreferences.Editor edit = sp.edit();
                        edit.putString("photourl" + sn, "");
                        edit.commit();

                    } else {
                        SharedPreferences sp = getSharedPreferences("SubSpecifiedLearningHomeActivity",
                                Context.MODE_PRIVATE);
                        SharedPreferences.Editor edit = sp.edit();
                        edit.putString("photourl" + sn, url);
                        edit.commit();
                    }
                } else if (rows.size() == 2) {
                    String url = specifiedPhotoBean.getRows().get(0).getUrl();
                    String url1 = specifiedPhotoBean.getRows().get(1).getUrl();
                    if (url == null) {
                        SharedPreferences sp = getSharedPreferences("SubSpecifiedLearningHomeActivity",
                                Context.MODE_PRIVATE);
                        SharedPreferences.Editor edit = sp.edit();
                        edit.putString("photourl" + sn, "");
                        edit.commit();
                    } else {
                        SharedPreferences sp = getSharedPreferences("SubSpecifiedLearningHomeActivity",
                                Context.MODE_PRIVATE);
                        SharedPreferences.Editor edit = sp.edit();
                        edit.putString("photourl" + sn, url);
                        edit.commit();
                        if (url1 == null) {
                            SharedPreferences sp1 = getSharedPreferences("SubSpecifiedLearningHomeActivity",
                                    Context.MODE_PRIVATE);
                            SharedPreferences.Editor edit1 = sp1.edit();
                            edit1.putString("photourl1" + sn, "");
                            edit1.commit();
                        } else {
                            SharedPreferences sp1 = getSharedPreferences("SubSpecifiedLearningHomeActivity",
                                    Context.MODE_PRIVATE);
                            SharedPreferences.Editor edit1 = sp1.edit();
                            edit1.putString("photourl1" + sn, url1);
                            edit1.commit();
                        }
                    }

                } else if (rows.size() == 3) {
                    String url = specifiedPhotoBean.getRows().get(0).getUrl();
                    String url1 = specifiedPhotoBean.getRows().get(1).getUrl();
                    String url2 = specifiedPhotoBean.getRows().get(2).getUrl();
                    if (url == null) {
                        SharedPreferences sp = getSharedPreferences("SubSpecifiedLearningHomeActivity",
                                Context.MODE_PRIVATE);
                        SharedPreferences.Editor edit = sp.edit();
                        edit.putString("photourl" + sn, "");
                        edit.commit();
                    } else {
                        SharedPreferences sp = getSharedPreferences("SubSpecifiedLearningHomeActivity",
                                Context.MODE_PRIVATE);
                        SharedPreferences.Editor edit = sp.edit();
                        edit.putString("photourl" + sn, url);
                        edit.commit();
                        if (url1 == null) {
                            SharedPreferences sp1 = getSharedPreferences("SubSpecifiedLearningHomeActivity",
                                    Context.MODE_PRIVATE);
                            SharedPreferences.Editor edit1 = sp1.edit();
                            edit1.putString("photourl1" + sn, "");
                            edit1.commit();
                        } else {
                            SharedPreferences sp1 = getSharedPreferences("SubSpecifiedLearningHomeActivity",
                                    Context.MODE_PRIVATE);
                            SharedPreferences.Editor edit1 = sp1.edit();
                            edit1.putString("photourl1" + sn, url1);
                            edit1.commit();
                            if (url2 == null) {
                                SharedPreferences sp2 = getSharedPreferences("SubSpecifiedLearningHomeActivity",
                                        Context.MODE_PRIVATE);
                                SharedPreferences.Editor edit2 = sp2.edit();
                                edit2.putString("photourl2" + sn, "");
                                edit2.commit();
                            } else {
                                SharedPreferences sp2 = getSharedPreferences("SubSpecifiedLearningHomeActivity",
                                        Context.MODE_PRIVATE);
                                SharedPreferences.Editor edit2 = sp2.edit();
                                edit2.putString("photourl2" + sn, url2);
                                edit2.commit();
                            }

                        }
                    }

                } else if (rows.size() == 4) {
                    String url = specifiedPhotoBean.getRows().get(0).getUrl();
                    String url1 = specifiedPhotoBean.getRows().get(1).getUrl();
                    String url2 = specifiedPhotoBean.getRows().get(2).getUrl();
                    String url3 = specifiedPhotoBean.getRows().get(3).getUrl();
                    if (url == null) {
                        SharedPreferences sp = getSharedPreferences("SubSpecifiedLearningHomeActivity",
                                Context.MODE_PRIVATE);
                        SharedPreferences.Editor edit = sp.edit();
                        edit.putString("photourl" + sn, "");
                        edit.commit();
                    } else {
                        SharedPreferences sp = getSharedPreferences("SubSpecifiedLearningHomeActivity",
                                Context.MODE_PRIVATE);
                        SharedPreferences.Editor edit = sp.edit();
                        edit.putString("photourl" + sn, url);
                        edit.commit();
                        if (url1 == null) {
                            SharedPreferences sp1 = getSharedPreferences("SubSpecifiedLearningHomeActivity",
                                    Context.MODE_PRIVATE);
                            SharedPreferences.Editor edit1 = sp1.edit();
                            edit1.putString("photourl1" + sn, "");
                            edit1.commit();
                        } else {
                            SharedPreferences sp1 = getSharedPreferences("SubSpecifiedLearningHomeActivity",
                                    Context.MODE_PRIVATE);
                            SharedPreferences.Editor edit1 = sp1.edit();
                            edit1.putString("photourl1" + sn, url1);
                            edit1.commit();
                            if (url2 == null) {
                                SharedPreferences sp2 = getSharedPreferences("SubSpecifiedLearningHomeActivity",
                                        Context.MODE_PRIVATE);
                                SharedPreferences.Editor edit2 = sp2.edit();
                                edit2.putString("photourl2" + sn, "");
                                edit2.commit();
                            } else {
                                SharedPreferences sp2 = getSharedPreferences("SubSpecifiedLearningHomeActivity",
                                        Context.MODE_PRIVATE);
                                SharedPreferences.Editor edit2 = sp2.edit();
                                edit2.putString("photourl2" + sn, url2);
                                edit2.commit();

                                if (url3 == null) {
                                    SharedPreferences sp3 = getSharedPreferences("SubSpecifiedLearningHomeActivity",
                                            Context.MODE_PRIVATE);
                                    SharedPreferences.Editor edit3 = sp3.edit();
                                    edit3.putString("photourl3" + sn, "");
                                    edit3.commit();
                                } else {
                                    SharedPreferences sp3 = getSharedPreferences("SubSpecifiedLearningHomeActivity",
                                            Context.MODE_PRIVATE);
                                    SharedPreferences.Editor edit3 = sp3.edit();
                                    edit3.putString("photourl3" + sn, url3);
                                    edit3.commit();
                                    ;
                                }
                            }

                        }
                    }

                } else if (rows.size() >= 5) {
                    String url = specifiedPhotoBean.getRows().get(0).getUrl();
                    String url1 = specifiedPhotoBean.getRows().get(1).getUrl();
                    String url2 = specifiedPhotoBean.getRows().get(2).getUrl();
                    String url3 = specifiedPhotoBean.getRows().get(3).getUrl();
                    String url4 = specifiedPhotoBean.getRows().get(4).getUrl();
                    if (url == null) {
                        SharedPreferences sp = getSharedPreferences("SubSpecifiedLearningHomeActivity",
                                Context.MODE_PRIVATE);
                        SharedPreferences.Editor edit = sp.edit();
                        edit.putString("photourl" + sn, "");
                        edit.commit();
                    } else {
                        SharedPreferences sp = getSharedPreferences("SubSpecifiedLearningHomeActivity",
                                Context.MODE_PRIVATE);
                        SharedPreferences.Editor edit = sp.edit();
                        edit.putString("photourl" + sn, url);
                        edit.commit();
                        if (url1 == null) {
                            SharedPreferences sp1 = getSharedPreferences("SubSpecifiedLearningHomeActivity",
                                    Context.MODE_PRIVATE);
                            SharedPreferences.Editor edit1 = sp1.edit();
                            edit1.putString("photourl1" + sn, "");
                            edit1.commit();
                        } else {
                            SharedPreferences sp1 = getSharedPreferences("SubSpecifiedLearningHomeActivity",
                                    Context.MODE_PRIVATE);
                            SharedPreferences.Editor edit1 = sp1.edit();
                            edit1.putString("photourl1" + sn, url1);
                            edit1.commit();
                            if (url2 == null) {
                                SharedPreferences sp2 = getSharedPreferences("SubSpecifiedLearningHomeActivity",
                                        Context.MODE_PRIVATE);
                                SharedPreferences.Editor edit2 = sp2.edit();
                                edit2.putString("photourl2" + sn, "");
                                edit2.commit();
                            } else {
                                SharedPreferences sp2 = getSharedPreferences("SubSpecifiedLearningHomeActivity",
                                        Context.MODE_PRIVATE);
                                SharedPreferences.Editor edit2 = sp2.edit();
                                edit2.putString("photourl2" + sn, url2);
                                edit2.commit();

                                if (url3 == null) {
                                    SharedPreferences sp3 = getSharedPreferences("SubSpecifiedLearningHomeActivity",
                                            Context.MODE_PRIVATE);
                                    SharedPreferences.Editor edit3 = sp3.edit();
                                    edit3.putString("photourl3" + sn, "");
                                    edit3.commit();
                                } else {
                                    SharedPreferences sp3 = getSharedPreferences("SubSpecifiedLearningHomeActivity",
                                            Context.MODE_PRIVATE);
                                    SharedPreferences.Editor edit3 = sp3.edit();
                                    edit3.putString("photourl3" + sn, url3);
                                    edit3.commit();
                                    ;
                                    if (url4 == null) {
                                        SharedPreferences sp4 = getSharedPreferences("SubSpecifiedLearningHomeActivity",
                                                Context.MODE_PRIVATE);
                                        SharedPreferences.Editor edit4 = sp4.edit();
                                        edit4.putString("photourl4" + sn, "");
                                        edit4.commit();
                                    } else {
                                        SharedPreferences sp4 = getSharedPreferences("SubSpecifiedLearningHomeActivity",
                                                Context.MODE_PRIVATE);
                                        SharedPreferences.Editor edit4 = sp4.edit();
                                        edit4.putString("photourl4" + sn, url4);
                                        edit4.commit();
                                    }
                                }


                            }

                        }
                    }

                }
            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {
                showToast("网络连接错误");
            }

            @Override
            public void onCancelled(CancelledException cex) {

            }

            @Override
            public void onFinished() {

            }
        });
    }
}
